package com.example.avmanagerweb.result.exceptionhandler;


import com.example.avmanagerweb.result.RLIST;
import com.example.avmanagerweb.result.RLISTconfig.ResultCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    //指定出现什么异常执行这个方法
    @ExceptionHandler(Exception.class)
    @ResponseBody //为了返回数据
    public RLIST error(Exception e) {
        e.printStackTrace();
        return RLIST.error().code(ResultCode.EXC).message("执行了全局异常处理..");
    }
    //特定异常
    //自定义异常
    @ExceptionHandler(JWException.class)
    @ResponseBody //为了返回数据
    public RLIST error(JWException e) {
        log.error(e.getMsg()+"---->吧错误写到Error文件中");//吧错误写到Error文件中
        e.printStackTrace();
        return RLIST.error().code(e.getCode()).message(e.getMsg());
    }
}
